package code1_100.code21_30;

import java.util.HashSet;

/**
 * @author 韩迪
 * @date 2022/03/28 19:56
 **/
public class Code26 {
    public int removeDuplicates(int[] nums) {

        int len = nums.length;
        HashSet<Integer> set = new HashSet<>();
        for (int i = nums.length-1; i >=0 ; i--) {
            if (set.contains(nums[i])){
                len--;
                move(nums,i);
            }else {
                set.add(nums[i]);
            }
        }
        return len;
    }

    public void swap(int[] arr,int a,int b){
        int t = arr[a];
        arr[a] = arr[b];
        arr[b] = t;
    }

    public void move(int[] arr,int a){
        for (int i = a; i < arr.length-1; i++) {
            swap(arr,i,i+1);
        }
    }

}
